#region License

// Copyright (c) 2013, ClearCanvas Inc.
// All rights reserved.
// http://www.clearcanvas.ca
//
// This file is part of the ClearCanvas RIS/PACS open source project.
//
// The ClearCanvas RIS/PACS open source project is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// The ClearCanvas RIS/PACS open source project is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// the ClearCanvas RIS/PACS open source project.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

// This file is auto-generated by the ClearCanvas.Model.SqlServer.CodeGenerator project.

namespace ClearCanvas.ImageServer.Model
{
    using System;
    using System.Xml;
    using ClearCanvas.Dicom;
    using ClearCanvas.Enterprise.Core;
    using ClearCanvas.ImageServer.Enterprise;
    using ClearCanvas.ImageServer.Enterprise.Command;
    using ClearCanvas.ImageServer.Model.EntityBrokers;

    [Serializable]
    public partial class FilesystemQueue: ServerEntity
    {
        #region Constructors
        public FilesystemQueue():base("FilesystemQueue")
        {}
        public FilesystemQueue(
             FilesystemQueueTypeEnum _filesystemQueueTypeEnum_
            ,ServerEntityKey _studyStorageKey_
            ,ServerEntityKey _filesystemKey_
            ,DateTime _scheduledTime_
            ,String _seriesInstanceUid_
            ,XmlDocument _queueXml_
            ):base("FilesystemQueue")
        {
            FilesystemQueueTypeEnum = _filesystemQueueTypeEnum_;
            StudyStorageKey = _studyStorageKey_;
            FilesystemKey = _filesystemKey_;
            ScheduledTime = _scheduledTime_;
            SeriesInstanceUid = _seriesInstanceUid_;
            QueueXml = _queueXml_;
        }
        #endregion

        #region Public Properties
        [EntityFieldDatabaseMappingAttribute(TableName="FilesystemQueue", ColumnName="FilesystemQueueTypeEnum")]
        public FilesystemQueueTypeEnum FilesystemQueueTypeEnum
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="FilesystemQueue", ColumnName="StudyStorageGUID")]
        public ServerEntityKey StudyStorageKey
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="FilesystemQueue", ColumnName="FilesystemGUID")]
        public ServerEntityKey FilesystemKey
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="FilesystemQueue", ColumnName="ScheduledTime")]
        public DateTime ScheduledTime
        { get; set; }
        [DicomField(DicomTags.SeriesInstanceUid, DefaultValue = DicomFieldDefault.Null)]
        [EntityFieldDatabaseMappingAttribute(TableName="FilesystemQueue", ColumnName="SeriesInstanceUid")]
        public String SeriesInstanceUid
        { get; set; }
        [EntityFieldDatabaseMappingAttribute(TableName="FilesystemQueue", ColumnName="QueueXml")]
        public XmlDocument QueueXml
        { get { return _QueueXml; } set { _QueueXml = value; } }
        [NonSerialized]
        private XmlDocument _QueueXml;
        #endregion

        #region Static Methods
        static public FilesystemQueue Load(ServerEntityKey key)
        {
            using (var context = new ServerExecutionContext())
            {
                return Load(context.ReadContext, key);
            }
        }
        static public FilesystemQueue Load(IPersistenceContext read, ServerEntityKey key)
        {
            var broker = read.GetBroker<IFilesystemQueueEntityBroker>();
            FilesystemQueue theObject = broker.Load(key);
            return theObject;
        }
        static public FilesystemQueue Insert(FilesystemQueue entity)
        {
            using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                FilesystemQueue newEntity = Insert(update, entity);
                update.Commit();
                return newEntity;
            }
        }
        static public FilesystemQueue Insert(IUpdateContext update, FilesystemQueue entity)
        {
            var broker = update.GetBroker<IFilesystemQueueEntityBroker>();
            var updateColumns = new FilesystemQueueUpdateColumns();
            updateColumns.FilesystemQueueTypeEnum = entity.FilesystemQueueTypeEnum;
            updateColumns.StudyStorageKey = entity.StudyStorageKey;
            updateColumns.FilesystemKey = entity.FilesystemKey;
            updateColumns.ScheduledTime = entity.ScheduledTime;
            updateColumns.SeriesInstanceUid = entity.SeriesInstanceUid;
            updateColumns.QueueXml = entity.QueueXml;
            FilesystemQueue newEntity = broker.Insert(updateColumns);
            return newEntity;
        }
        #endregion
    }
}
